﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KpBusiness.Model;
using KpBusiness.Service;
using WebApp.Utility;

namespace KpMis.Controllers
{ 
    public class PositionController : Controller
    {
        
        
        //
        // GET: /Position/

        public ViewResult Index()
        {
            return View(new PositionService().GetAllPositions());
        }

        //
        // GET: /Position/Details/5

        public ViewResult Details(int id)
        {
            Position position = new PositionService().GetPosition(id);
            return View(position);
        }

        //
        // GET: /Position/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Position/Create

        [HttpPost]
        [ValidateOnlyIncomingValuesAttribute]
        public ActionResult Create(Position position)
        {
            if (ModelState.IsValid)
            {
                new PositionService().SavePosition(position); 
                return RedirectToAction("Index");  
            }

            return View(position);
        }
        
        //
        // GET: /Position/Edit/5
 
        public ActionResult Edit(int id)
        {
            Position position = new PositionService().GetPosition(id);  
            return View(position);
        }

        //
        // POST: /Position/Edit/5

        [HttpPost]
        [ValidateOnlyIncomingValues]
        public ActionResult Edit(Position position)
        {
            if (ModelState.IsValid)
            {
                new PositionService().SavePosition(position); 
                return RedirectToAction("Index");
            }
            return View(position);
        }

        //
        // GET: /Position/Delete/5
 
        //public ActionResult Delete(int id)
        //{
        //    Position position = db.Positions.Find(id);
        //    return View(position);
        //}

        //
        // POST: /Position/Delete/5

        //[HttpPost, ActionName("Delete")]
        //public ActionResult DeleteConfirmed(int id)
        //{            
        //    Position position = db.Positions.Find(id);
        //    db.Positions.Remove(position);
        //    db.SaveChanges();
        //    return RedirectToAction("Index");
        //}

        protected override void Dispose(bool disposing)
        {
           
            base.Dispose(disposing);
        }
    }
}